package com.example.bigwork.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/api/**") // Define the path pattern for CORS
                .allowedOrigins("*")       // Allow requests from any origin (for development, be more specific in production)
                .allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS") // Allowed HTTP methods
                .allowedHeaders("*")       // Allowed headers
                .allowCredentials(false)   // If true, allowedOrigins cannot be "*"
                .maxAge(3600);             // Cache pre-flight response for 1 hour
    }
}
